{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "X_train shape: (25000, 400) X_test shape: (25000, 400)\n",
      "WARNING:tensorflow:From /usr/local/lib/python3.6/site-packages/tensorflow/python/util/deprecation.py:497: calling conv1d (from tensorflow.python.ops.nn_ops) with data_format=NHWC is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "`NHWC` for data_format is deprecated, use `NWC` instead\n",
      "Train 25000 samples | Test 25000 samples\n",
      "Epoch 1/2 | Step 50/781 | train_loss: 0.6570 | train_acc: 0.6250 | lr: 0.0048\n",
      "Epoch 1/2 | Step 100/781 | train_loss: 0.4431 | train_acc: 0.8125 | lr: 0.0045\n",
      "Epoch 1/2 | Step 150/781 | train_loss: 0.3275 | train_acc: 0.8438 | lr: 0.0043\n",
      "Epoch 1/2 | Step 200/781 | train_loss: 0.5079 | train_acc: 0.7500 | lr: 0.0041\n",
      "Epoch 1/2 | Step 250/781 | train_loss: 0.2532 | train_acc: 0.9062 | lr: 0.0039\n",
      "Epoch 1/2 | Step 300/781 | train_loss: 0.3199 | train_acc: 0.8750 | lr: 0.0037\n",
      "Epoch 1/2 | Step 350/781 | train_loss: 0.2042 | train_acc: 0.9375 | lr: 0.0035\n",
      "Epoch 1/2 | Step 400/781 | train_loss: 0.2135 | train_acc: 0.9062 | lr: 0.0033\n",
      "Epoch 1/2 | Step 450/781 | train_loss: 0.4032 | train_acc: 0.8125 | lr: 0.0032\n",
      "Epoch 1/2 | Step 500/781 | train_loss: 0.1931 | train_acc: 0.9062 | lr: 0.0030\n",
      "Epoch 1/2 | Step 550/781 | train_loss: 0.3441 | train_acc: 0.8750 | lr: 0.0028\n",
      "Epoch 1/2 | Step 600/781 | train_loss: 0.2623 | train_acc: 0.8750 | lr: 0.0027\n",
      "Epoch 1/2 | Step 650/781 | train_loss: 0.1903 | train_acc: 0.9375 | lr: 0.0026\n",
      "Epoch 1/2 | Step 700/781 | train_loss: 0.2341 | train_acc: 0.9062 | lr: 0.0024\n",
      "Epoch 1/2 | Step 750/781 | train_loss: 0.1735 | train_acc: 0.9375 | lr: 0.0023\n",
      "Epoch 1/2 | train_loss: 0.1270 | train_acc: 1.0000 | test_loss: 0.2989 | test_acc: 0.8746 | lr: 0.0022\n",
      "Epoch 2/2 | Step 50/781 | train_loss: 0.3986 | train_acc: 0.8750 | lr: 0.0021\n",
      "Epoch 2/2 | Step 100/781 | train_loss: 0.1239 | train_acc: 0.9375 | lr: 0.0020\n",
      "Epoch 2/2 | Step 150/781 | train_loss: 0.3092 | train_acc: 0.9375 | lr: 0.0019\n",
      "Epoch 2/2 | Step 200/781 | train_loss: 0.1195 | train_acc: 1.0000 | lr: 0.0018\n",
      "Epoch 2/2 | Step 250/781 | train_loss: 0.0971 | train_acc: 1.0000 | lr: 0.0017\n",
      "Epoch 2/2 | Step 300/781 | train_loss: 0.0592 | train_acc: 1.0000 | lr: 0.0016\n",
      "Epoch 2/2 | Step 350/781 | train_loss: 0.2575 | train_acc: 0.8750 | lr: 0.0016\n",
      "Epoch 2/2 | Step 400/781 | train_loss: 0.1028 | train_acc: 0.9375 | lr: 0.0015\n",
      "Epoch 2/2 | Step 450/781 | train_loss: 0.1366 | train_acc: 0.9688 | lr: 0.0014\n",
      "Epoch 2/2 | Step 500/781 | train_loss: 0.2158 | train_acc: 0.9375 | lr: 0.0013\n",
      "Epoch 2/2 | Step 550/781 | train_loss: 0.1213 | train_acc: 0.9688 | lr: 0.0013\n",
      "Epoch 2/2 | Step 600/781 | train_loss: 0.4530 | train_acc: 0.8125 | lr: 0.0012\n",
      "Epoch 2/2 | Step 650/781 | train_loss: 0.1919 | train_acc: 0.9688 | lr: 0.0011\n",
      "Epoch 2/2 | Step 700/781 | train_loss: 0.2432 | train_acc: 0.9062 | lr: 0.0011\n",
      "Epoch 2/2 | Step 750/781 | train_loss: 0.3582 | train_acc: 0.9062 | lr: 0.0010\n",
      "Epoch 2/2 | train_loss: 0.1046 | train_acc: 1.0000 | test_loss: 0.2522 | test_acc: 0.8997 | lr: 0.0010\n",
      "             precision    recall  f1-score   support\n",
      "\n",
      "          0       0.91      0.88      0.90     12500\n",
      "          1       0.89      0.92      0.90     12500\n",
      "\n",
      "avg / total       0.90      0.90      0.90     25000\n",
      "\n"
     ]
    }
   ],
   "source": [
    "from __future__ import print_function\n",
    "from concat_conv_1d_text_clf import Conv1DClassifier\n",
    "from sklearn.metrics import classification_report\n",
    "import tensorflow as tf\n",
    "import numpy as np\n",
    "\n",
    "\n",
    "vocab_size = 5000\n",
    "seq_len = 400\n",
    "n_out = 2\n",
    "\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    (X_train, y_train), (X_test, y_test) = tf.keras.datasets.imdb.load_data(num_words=vocab_size)\n",
    "\n",
    "    X_train = tf.keras.preprocessing.sequence.pad_sequences(X_train, maxlen=seq_len)\n",
    "    X_test = tf.keras.preprocessing.sequence.pad_sequences(X_test, maxlen=seq_len)\n",
    "    print('X_train shape:', X_train.shape, 'X_test shape:', X_test.shape)\n",
    "\n",
    "    clf = Conv1DClassifier(seq_len, vocab_size, n_out)\n",
    "    log = clf.fit(X_train, y_train, n_epoch=2, batch_size=32, keep_prob=0.8, en_exp_decay=True,\n",
    "                  val_data=(X_test, y_test)) \n",
    "\n",
    "    print(classification_report(y_test, clf.predict(X_test)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
